package com.itheima.controller.admin;


import com.itheima.dto.OrdersStatisticsDto;
import com.itheima.feign.OrderClient;
import com.itheima.vo.OrderReportVO;
import com.itheima.result.Result;
import com.itheima.service.ReportService;
import com.itheima.vo.SalesTop10ReportVO;
import com.itheima.vo.TurnoverReportVO;
import com.itheima.vo.UserReportVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/report")
@Slf4j
@Api(tags = "统计分析相关接口")
public class ReportController {


//    @Autowired
//    private OrderService orderService;

    @Autowired
    private OrderClient orderClient;

    @Autowired
    private ReportService reportService;



    /**
     * 订单统计
     *
     * @param statisticsDto
     * @return
     */
    @GetMapping("/ordersStatistics")
    public Result orderStatistics(OrdersStatisticsDto statisticsDto) {
        log.info("statisticsDto为{}", statisticsDto);
//        OrderReportVO vo = orderService.orderStatistics(statisticsDto);
        Result<OrderReportVO> result = orderClient.orderStatistics(statisticsDto);
        OrderReportVO vo = result.getData();
        return Result.success(vo);
    }

    /**
     * 营业额统计接口
     *
     * @param statisticsDto
     * @return
     */
    @GetMapping("/turnoverStatistics")
    public Result turnoverStatistics(OrdersStatisticsDto statisticsDto) {
        log.info("statisticsDto为{}", statisticsDto);
        TurnoverReportVO vo = reportService.turnoverStatistics(statisticsDto);
        return Result.success(vo);
    }

    /**
     * 用户统计接口
     * @param statisticsDto
     * @return
     */
    @GetMapping("/userStatistics")
    public Result userStatistics(OrdersStatisticsDto statisticsDto) {
        log.info("statisticsDto为{}", statisticsDto);
        UserReportVO userReportVO = reportService.userStatistics(statisticsDto);
        return Result.success(userReportVO);
    }

    /**
     * 查询销量排名top10接口
     * @param dto
     * @return
     */
    @GetMapping("/top10")
    public Result top(OrdersStatisticsDto dto){
        log.info("dto为{}", dto);
//        SalesTop10ReportVO vo=orderService.top(dto);
        Result<SalesTop10ReportVO> result = orderClient.top(dto);
        SalesTop10ReportVO vo = result.getData();
        return Result.success(vo);
    }

//    /**
//     * 导出Excel报表接口
//     * @param response
//     */
//    @GetMapping("/export")
//    public void export(HttpServletResponse response) throws Exception {
//        reportService.exportBusinessData(response);
//    }
}
